define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'cms/plaza_post/index' + location.search,
                    add_url: 'cms/plaza_post/add',
                    edit_url: 'cms/plaza_post/edit',
                    del_url: 'cms/plaza_post/del',
                    multi_url: 'cms/plaza_post/multi',
                    import_url: 'cms/plaza_post/import',
                    table: 'plaza_post',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                fixedColumns: true,
                fixedRightNumber: 1,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'postname', title: __('Postname'), operate: 'LIKE'},
                        // {field: 'postcontent', title: __('Postcontent')},
                        {field: 'scraping_text_link', title: __('Scraping_text_link'), operate: 'LIKE'},
                        // {field: 'username', title: __('Username'), operate: 'LIKE'},
                        {field: 'user_id', title: __('User_id')},
                        {field: 'category_name', title: __('Plaza_category_id')},
                        {field: 'view', title: __('View'), operate: 'LIKE'},
                        {field: 'lock', title: __('Lock'),
                            align: 'center',
                            table: table,
                            formatter: Table.api.formatter.toggle
                        },
                        {
                            field: 'top', title: __('Top'),
                            // operate: 'LIKE',
                            align: 'center',
                            table: table,
                            formatter: Table.api.formatter.toggle
                        },
                        {
                            field: 'is_jing',
                            title: __('Is_jing'),
                            align: 'center',
                            table: table,
                            formatter: Table.api.formatter.toggle
                        },
                        {
                            field: 'is_audit',
                            title: __('Is_audit'),
                            align: 'center',
                            table: table,
                            formatter: Table.api.formatter.toggle
                        },
                        {field: 'replytime', title: __('Replytime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false},
                        // {field: 'appid', title: __('Appid')},
                        {field: 'comment_count', title: __('Comment_count')},
                        {field: 'membership_price', title: __('Membership_price')},
                        {field: 'membership_duration', title: __('Membership_duration')},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false},
                        {field: 'updatetime', title: __('Updatetime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false},
                        // {field: 'category.id', title: __('Category.id')},
                        // {field: 'category.pid', title: __('Category.pid')},
                        // {field: 'category.platename', title: __('Category.platename'), operate: 'LIKE'},
                        // {field: 'category.plateicon', title: __('Category.plateicon'), operate: 'LIKE', formatter: Table.api.formatter.icon},
                        // {field: 'category.iscomment', title: __('Category.iscomment')},
                        // {field: 'category.appid', title: __('Category.appid')},
                        // {field: 'category.admin', title: __('Category.admin'), operate: 'LIKE'},
                        // {field: 'category.plateontent', title: __('Category.plateontent'), operate: 'LIKE'},
                        // {field: 'category.list_order', title: __('Category.list_order')},
                        // {field: 'category.status', title: __('Category.status')},
                        // {field: 'category.plategg', title: __('Category.plategg'), operate: 'LIKE'},
                        // {field: 'category.creattime', title: __('Category.creattime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false},
                        // {field: 'category.updatetime', title: __('Category.updatetime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false},
                        // {field: 'category.deletetime', title: __('Category.deletetime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        recyclebin: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    'dragsort_url': ''
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: 'cms/plaza_post/recyclebin' + location.search,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {
                            field: 'deletetime',
                            title: __('Deletetime'),
                            operate: 'RANGE',
                            addclass: 'datetimerange',
                            formatter: Table.api.formatter.datetime
                        },
                        {
                            field: 'operate',
                            width: '140px',
                            title: __('Operate'),
                            table: table,
                            events: Table.api.events.operate,
                            buttons: [
                                {
                                    name: 'Restore',
                                    text: __('Restore'),
                                    classname: 'btn btn-xs btn-info btn-ajax btn-restoreit',
                                    icon: 'fa fa-rotate-left',
                                    url: 'cms/plaza_post/restore',
                                    refresh: true
                                },
                                {
                                    name: 'Destroy',
                                    text: __('Destroy'),
                                    classname: 'btn btn-xs btn-danger btn-ajax btn-destroyit',
                                    icon: 'fa fa-times',
                                    url: 'cms/plaza_post/destroy',
                                    refresh: true
                                }
                            ],
                            formatter: Table.api.formatter.operate
                        }
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },

        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
